package com.heima.wemedia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wenmedia.pojos.WmUser;;
import com.heima.wemedia.mapper.WemediaMapper;
import com.heima.wemedia.service.Wemdiaservice;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class WemdiaImpl extends ServiceImpl<WemediaMapper, WmUser> implements Wemdiaservice {

    @Override
    public ResponseResult findbyname(String name) {
        if (StringUtils.isBlank(name)) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        LambdaQueryWrapper<WmUser> wrapper = Wrappers.lambdaQuery();
        WmUser user = getOne(wrapper.eq(WmUser::getName, name));

        return ResponseResult.okResult(user);
    }

    @Override
    public ResponseResult wemsave(WmUser wmUser) {
        save(wmUser);
        return ResponseResult.okResult(wmUser);
    }

}
